package Year2021.Month11.Day1Homework.Day3;

import java.util.Arrays;
import java.util.Scanner;

public class Game {
    private String name;

    public void printStr() {
        Player p = new Player("老王", 1);
        int score = 0;//分;
        int NO = 1;//级别;
        while (true) {
            if (p.getLevelNo() < 6) {
                char a[] = new char[3];
                int i;
                for (i = 0; i < a.length; i++) {
                    a[i] = (char) (Math.random() * (127 - 32) + 32);//产生随机字符串;
                    System.out.print(a[i] + "\t");
                }
                System.out.println();
                Scanner in = new Scanner(System.in);
                System.out.println("请按照提示打字符!");
                Long start = System.currentTimeMillis();
                String b = in.next();
                Long end = System.currentTimeMillis();
                if ((end - start) > 10000) {
                    System.out.println("闯关失败，退出游戏");
                    return;
                }
                char c[] = b.toCharArray();//将b转换为char类型;
                boolean flag = Arrays.equals(a, c);
                if (flag) {
                    score++;
                    p.setCurrScore(score);
                    if (p.getCurrScore() == 4) {
                        NO++;
                        p.setLevelNo(NO);
                        score = 0;
                        p.setCurrScore(0);
                    }
                    System.out.println("输入正确" + "\t" + "您的积分为" + p.getCurrScore() + "分" + "\t" + "您的级别为" +
                            p.getLevelNo() + "\t" + "已用的时间为" + (end - start) + "毫秒");

                } else {
                    System.out.println("输入错误,闯关失败，退出！");
                    return;
                }

            } else if (p.getLevelNo() >= 6) {
                System.out.println("恭喜您通关了！！");
                return;
            }
        }
    }


}

